package cn.momoshenchi.controller;

import cn.momoshenchi.ResultInfo;
import cn.momoshenchi.pojo.OrganizationsStudent;
import cn.momoshenchi.pojo.StudentGpa;
import cn.momoshenchi.service.OrganizationService;
import cn.momoshenchi.service.OrganizationsStudentService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @version : 1.0
 * @author: momoshenchi
 * @date: 2021/6/6 - 11:54
 */
@Controller
@Api("学生社团")
public class StudentOrgController
{
    @Autowired
    private OrganizationsStudentService organizationsStudentService;

    @Autowired
    private AmqpTemplate template;

    public  ResultInfo success()
    {
        return  new ResultInfo();
    }

    @GetMapping("studentOrg")
    public String page()
    {
        return  "/view/studentOrg.html";
    }

    @Operation(summary="查询社团")
    @GetMapping("studentOrg/list")
    @ResponseBody
    public ResultInfo list(int page,int size)
    {
        IPage<OrganizationsStudent> page1=new Page<OrganizationsStudent>();
        page1.setPages(page);
        page1.setSize(size);
        page1 = organizationsStudentService.page(page1);
        ResultInfo resultInfo=new ResultInfo();
        resultInfo.setResult(page1.getRecords());
        return  resultInfo;
    }
    @Operation(summary="添加社团")
    @PostMapping("studentOrg")
    @PreAuthorize("hasAuthority('student:add')")
    @ResponseBody
    public  ResultInfo post( @RequestBody OrganizationsStudent student )
    {
        organizationsStudentService.save(student);
//        template.convertAndSend("MyExchange","","已收到");
        System.out.println("Sender : " + student);
        return  success();
    }
}
